#!/bin/bash


#Muestra el informe compilado.


#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#Cambiar acá las opciones del target.

informname="TP1_Informe"
targetdir="./../informe-compilado"

################################################################################


if test "$1" != ""; then
	echo "Error: No arguments expected."
	echo
	exit 1;
fi


#******************************************************
informtex="$informname.tex"
informaux="$informname.aux"
informpdf="$informname.pdf"
informlog="$informname.log"
informpdfmoved="$targetdir/$informpdf"
premisesmoved="$targetdir/$premises"

informcmd="mv"

latexcmd="pdflatex"
bibcmd="bibtex"
thumbcmd="thumbpdf"
#opencmd="/usr/bin/xdg-open"
opencmd="xdg-open"
newsession="setsid"
#******************************************************

#******************************************************
DONE="Done."

PRESSANYKEY="Press any key to continue..."
OPENNINGTARGETFILE="Openning file: \"$informpdfmoved\"..."

ERROROPENNINGTARGET="Error openning the file: \"$informpdfmoved\"."
ERRORXDGNOTINSTALLED="Error, \"$opencmd\" not installed in the system."
#******************************************************


function pause(){
	echo
	read -p "$PRESSANYKEY"
}

which  >/dev/null 2>/dev/null "$opencmd"

if [ $? -ne 0 ] ; then
	echo
	echo "$ERRORXDGNOTINSTALLED"
	pause
	exit 2
fi


echo
echo "$OPENNINGTARGETFILE"
$newsession > /dev/null 2>/dev/null "$opencmd" > /dev/null 2>/dev/null "$informpdfmoved"

if [ $? -ne 0 ] ; then

	echo
	echo "$ERROROPENNINGTARGET"
	pause
	exit 3

else

	echo "$DONE"
	echo
	pause
	exit 0

fi

